#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QPushButton>
#include <QDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPushButton* btn1 = new QPushButton("模态对话框", this);
    QPushButton* btn2 = new QPushButton("非模态对话框", this);
    QPushButton* btn3 = new QPushButton("混合对话框", this);

    btn1->move(50, 100);
    btn2->move(200, 100);
    btn3->move(350, 100);

    // 创建模态对话框
    connect(btn1, &QPushButton::clicked, [=](){
         QDialog* dlg = new QDialog(this);
         dlg->resize(200,100);
         dlg->exec();
    });

    // 创建非模态对话框
    connect(btn2, &QPushButton::clicked, [=](){
        QDialog* dlg = new QDialog(this);
        dlg->resize(200,100);

        dlg->setAttribute(Qt::WA_DeleteOnClose);

        dlg->show();
    });

    connect(btn3, &QPushButton::clicked, [=](){
        QDialog* dlg = new QDialog(this);
        dlg->setAttribute(Qt::WA_DeleteOnClose);

        dlg->resize(200,100);

        dlg->setModal(true);

        dlg->show();
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

